/*
 * Hidden Equity LLC
 * Author: Maksym Fedyay, Kyiv, mcsimf@gmail.com
 * Date: 29.02.2012
 */

package com.hiddenequity.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class DateProcessor {

	public static final int TODAY = 1;
	public static final int YESTERDAY = 2;
	public static final int THIS_WEEK_SUN_TODAY = 3;
	public static final int THIS_WEEK_MON_TODAY = 4;
	public static final int LAST_SEVEN_DAYS = 5;
	public static final int LAST_WEEK_SUN_SAT = 6;
	public static final int LAST_WEEK_MON_SUN = 7;
	public static final int LUST_BUS_WEEK = 8;
	public static final int LAST_14_DAYS =9;
	public static final int THIS_MONTH = 10;
	public static final int LAST_30_DAYS = 11;
	public static final int LAST_MONTH = 12;
	public static final int ALL_TIME = 0;
	

	public static ArrayList<String> getDateRange(int range){
		
		ArrayList<String> dateRange = new ArrayList<String>();
		
		Date today = new Date(); 
		today.getTime();
		
		int presentDayOfWeek = today.getDay();
		int presentDayOfMonth = today.getDate();
		
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");

		String start = "";
		String end = "";
		
    	switch (range) {
    	
	        case TODAY: 
	        	dateRange.add(df.format(today));
	        	dateRange.add(df.format(today));
	        	break;
	            
	        case YESTERDAY: 
	        	today.setDate(presentDayOfMonth - 1);
	        	Date yesterday = today;
	        	dateRange.add(df.format(yesterday));
	        	dateRange.add(df.format(yesterday));
	        	break;
	        	
	        case THIS_WEEK_SUN_TODAY:
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - presentDayOfWeek);
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case THIS_WEEK_MON_TODAY: 
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - presentDayOfWeek + 1);
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case LAST_SEVEN_DAYS: 
	        	today.setDate(presentDayOfMonth - 1);
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - 7);
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case LAST_WEEK_SUN_SAT: 
	        	today.setDate(presentDayOfMonth - (presentDayOfWeek + 1));
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - (presentDayOfWeek + 7));
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case LAST_WEEK_MON_SUN: 
	        	today.setDate(presentDayOfMonth - presentDayOfWeek);
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - (presentDayOfWeek + 6));
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case LUST_BUS_WEEK: 
	        	today.setDate(presentDayOfMonth - (presentDayOfWeek + 2));
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - (presentDayOfWeek + 6));
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case LAST_14_DAYS: 
	        	today.setDate(presentDayOfMonth - 1);
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - 14);
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case THIS_MONTH: 
	        	today.setDate(presentDayOfMonth);
	        	end = df.format(today);
	        	today.setDate(1);
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case LAST_30_DAYS: 
	        	today.setDate(presentDayOfMonth - 1);
	        	end = df.format(today);
	        	today.setDate(presentDayOfMonth - 30);
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case LAST_MONTH: 
	        	today.setDate(presentDayOfMonth - presentDayOfMonth);
	        	end = df.format(today);
	        	today.setDate(1);
	        	start = df.format(today);
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        case ALL_TIME: 
	        	dateRange.add(start);
	        	dateRange.add(end);
	        	break;
	        	
	        default:
	        	dateRange.add(start);
	        	dateRange.add(end);
    	} 

		return dateRange;
	}

}
